﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model.WeiXin;
using Model.WXshopBuiness;
using Model.WXshopBuiness.Enum;
using Services.Util;
using Services.WeiXinProject;
using Services.WXshopBuiness;
using Xproject.Util;

namespace WeiXinProject.Controllers
{
    public class TestController : Controller
    {
        IdentityServices m_WeiXinServices;
        UserInfoServices userinfoservice;
        WXOrderServices m_WXOrderServices;
        UserInfoServices m_UserInfoServices;
        WeiXinMessageServices m_wxmessageServices;
        public TestController(IdentityServices mWeiXinServices,UserInfoServices userinfo, WXOrderServices mWXOrderServices, UserInfoServices mUserInfoServices, WeiXinMessageServices mwxmessageServices)
        {
            m_WeiXinServices = mWeiXinServices;
            userinfoservice = userinfo;
            m_WXOrderServices = mWXOrderServices;
            m_wxmessageServices = mwxmessageServices;
            m_UserInfoServices = mUserInfoServices;
        }


        public ActionResult image()
        {
          
            QRcodeHelper.CreateProductTuiGuangQRcode("http://www.weixin.com/Upload/Images/20180906/productdetail?productid=44a09fde-47e8-4f1d-a317-b9ea206b0aa1&wxip=023",
               @"D:\Csharp\2018\WeiXinProject\WeiXinpProAdmin\Upload\Images\20180824\0afb8767-4833-4914-9331-59897976bb24.jpg",
               "耐克2018款新上架的鞋子",
               "",
               "799.00","1999.00",
               @"D:\Csharp\2018\WeiXinProject\WeiXinpProAdmin\Upload\img", "aaa.jpg");
            return View();
        }
        // GET: Test
        public ActionResult Index()
        {
            // m_WeiXinServices.InsertAnUserId("abcd");
            //Identity identity = m_WeiXinServices.GetByUserId("abcd");
            //userinfoservice.InsertWeiXinUserInfo("nickname", "openid", "headurl", "area", "sex", "uniond", "parent");
            //userinfoservice.InserWeiXinUserInfo_ZX("nickname", "openid", "headurl", "area", "sex", "uniond", "parent", null, null, "LSG", 0);
            WeiXinOrder order = m_WXOrderServices.GetDBOrderById("2ed520e4da374184a3407eb94b962c24");  //得到当前的order 信息
            OrderChangeHistory history = new OrderChangeHistory();
            history.OrderId = order.OrderID;
            history.OrderMoney = order.OrderMoney;
            history.StateBefore = order.OrderState;
            history.StateAfter = (int)Enum_OrderState.PAYED;
            history.Remarks = "微信支付完毕！订单由待支付 -->已支付";
            order.OrderState = (int)Enum_OrderState.PAYED;
            if (m_WXOrderServices.WeiXinPaySuccess(order, history))
            {
                WeiXinUser user = m_UserInfoServices.GetById(order.UserID);
                string domain = CommonHelper.GetAppSettings("Domain");
                string url = domain + "/Order/PayOrderDetail?orderId=" + order.OrderID;
                m_wxmessageServices.SendOrderPaySuccessMessage(CommonHelper.GetAppSettings("MessageSender"), "", order.UserID, user.OpenId,
                   url, CommonHelper.GetAppSettings("WeiXin_APPID"), user.NickName, order.OrderName, order.OrderCode,order.OrderMoney.ToString());
                return View();
            }
            return View();
        }
    }
}